﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Drawing;

namespace Toybox.NicoSharp.Message
{
  /// <summary>
  /// 位置
  /// </summary>
  public enum Position
  {
    /// <summary>
    /// 未指定
    /// </summary>
    NotSet,

    naka,
    ue,
    shita,
  }

  /// <summary>
  /// サイズ
  /// </summary>
  public enum CommentSize
  {
    /// <summary>
    /// 未指定
    /// </summary>
    NotSet,

    /// <summary>
    /// 通常サイズ
    /// </summary>
    medium,

    /// <summary>
    /// 大きいサイズ
    /// </summary>
    big,

    /// <summary>
    /// 小さいサイズ
    /// </summary>
    small,
  }

  /// <summary>
  /// 色
  /// </summary>
  public enum NicoColor
  {
    /// <summary>
    /// 未指定
    /// </summary>
    NotSet,

    #region 一般
    white,
    red,
    pink,
    orange,
    yellow,
    green,
    cyan,
    blue,
    purple,
    black,
    #endregion
    #region プレミアム
    white2,
    niconicowhite,
    red2,
    truered,
    orange2,
    passionorange,
    yellow2,
    madyellow,
    green2,
    elementalgreen,
    blue2,
    marineblue,
    purple2,
    nobleviolet,
    #endregion
  }

  public class Mail : INotifyPropertyChanged
  {

    #region [Static]

    /// <summary>
    /// 色リスト
    /// </summary>
    public static Color[] NicoColorList = new Color[]
    {
      Color.Empty,

      ColorTranslator.FromHtml("#FFFFFF"),  //white
      ColorTranslator.FromHtml("#FF0000"),  //red
      ColorTranslator.FromHtml("#FF7788"),  //pink
      ColorTranslator.FromHtml("#FFAA00"),  //orange

      ColorTranslator.FromHtml("#FFFF00"),  //yellow
      ColorTranslator.FromHtml("#33FF00"),  //green
      ColorTranslator.FromHtml("#00FFFF"),  //cyan
      ColorTranslator.FromHtml("#1199FF"),  //blue
      
      ColorTranslator.FromHtml("#CC3388"),  //purple
      ColorTranslator.FromHtml("#CCCCCC"),  
      ColorTranslator.FromHtml("#CC0033"),
      ColorTranslator.FromHtml("#FF33CC"),
      
      ColorTranslator.FromHtml("#FF6633"),
      ColorTranslator.FromHtml("#CCCC00"),
      ColorTranslator.FromHtml("#00CC66"),
      ColorTranslator.FromHtml("#33CCCC"),
      
      ColorTranslator.FromHtml("#3366FF"),
      ColorTranslator.FromHtml("#9900FF"),
      ColorTranslator.FromHtml("#666666"),
      ColorTranslator.FromHtml("#000000"),
    };

    #endregion [Static]

    #region [INotifyPropertyChanged]

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string property)
    {
      if (PropertyChanged != null)
        PropertyChanged(this, new PropertyChangedEventArgs(property));
    }

    #endregion [INotifyPropertyChanged]


    #region Constructor

    public Mail()
    {

    }

    public Mail(string mail)
    {
      this.Decode(mail);
    }

    #endregion Constructor


    #region Public Members

    public CommentSize Size
    {
      get { return _size; }
      set
      {
        if (_size == value) return;

        _size = value;

        OnPropertyChanged("Size");
      }
    }
    private CommentSize _size;

    public Position position
    {
      get { return _position; }
      set
      {
        if (_position == value) return;

        _position = value;

        OnPropertyChanged("position");
      }
    }
    public Position _position;

    public NicoColor color
    {
      get { return _color; }
      set
      {
        if (_color == value) return;

        _color = value;

        OnPropertyChanged("color");
      }
    }
    public NicoColor _color;

    public string colorText
    {
      get { return _colorText; }
      set
      {
        if (_colorText == value) return;

        _colorText = value;

        OnPropertyChanged("colorText");
      }
    }
    public string _colorText;

    public bool is184
    {
      get { return _is184; }
      set
      {
        if (_is184 == value) return;

        _is184 = value;

        OnPropertyChanged("is184");
      }
    }
    public bool _is184;

    public bool sage
    {
      get { return _sage; }
      set
      {
        if (_sage == value) return;

        _sage = value;

        OnPropertyChanged("sage");
      }
    }
    public bool _sage;

    public bool invisible
    {
      get { return _invisible; }
      set
      {
        if (_invisible == value) return;

        _invisible = value;

        OnPropertyChanged("invisible");
      }
    }
    public bool _invisible;

    public bool from_button
    {
      get { return _from_button; }
      set
      {
        if (_from_button == value) return;

        _from_button = value;

        OnPropertyChanged("from_button");
      }
    }
    public bool _from_button;

    public bool is_button
    {
      get { return _is_button; }
      set
      {
        if (_is_button == value) return;

        _is_button = value;

        OnPropertyChanged("is_button");
      }
    }
    public bool _is_button;

    public bool mobile
    {
      get { return _mobile; }
      set
      {
        if (_mobile == value) return;

        _mobile = value;

        OnPropertyChanged("mobile");
      }
    }
    public bool _mobile;

    public bool all
    {
      get { return _all; }
      set
      {
        if (_all == value) return;

        _all = value;

        OnPropertyChanged("all");
      }
    }
    public bool _all;


    #endregion Public Members

    #region Protected Members

    #endregion Protected Members

    #region Private Members

    #endregion Private Members


    #region Public Methods

    #endregion Public Methods

    #region Protected Methods

    #region Override Methods
    
    protected virtual void Decode(string text)
    {
      string[] temp = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

      for (int n = 0; n < temp.Length; n++)
      {
        switch (temp[n])
        {
          #region サイズ
          case "big":
            this.Size = CommentSize.big; break;
          case "medium":
            this.Size = CommentSize.medium; break;
          case "small":
            this.Size = CommentSize.small; break;
          #endregion
          #region 位置
          case "ue":
            this.position = Position.ue; break;
          case "shita":
            this.position = Position.shita; break;
          case "naka":
            this.position = Position.naka; break;
          #endregion
          #region 共通カラー
          case "white":
            this.color = NicoColor.white; break;
          case "red":
            this.color = NicoColor.red; break;
          case "pink":
            this.color = NicoColor.pink; break;
          case "orange":
            this.color = NicoColor.orange; break;
          case "yellow":
            this.color = NicoColor.yellow; break;
          case "green":
            this.color = NicoColor.green; break;
          case "cyan":
            this.color = NicoColor.cyan; break;
          case "blue":
            this.color = NicoColor.blue; break;
          case "purple":
            this.color = NicoColor.purple; break;
          case "black":
            this.color = NicoColor.black; break;
          #endregion
          #region プレミアムカラー
          case "niconicowhite":
          case "white2":
            this.color = NicoColor.white2; break;
          case "truered":
          case "red2":
            this.color = NicoColor.red2; break;
          case "passionorange":
          case "orange2":
            this.color = NicoColor.orange2; break;
          case "madyellow":
          case "yellow2":
            this.color = NicoColor.yellow2; break;
          case "elementalgreen":
          case "green2":
            this.color = NicoColor.green2; break;
          case "marineblue":
          case "blue2":
            this.color = NicoColor.blue2; break;
          case "nobleviolet":
          case "purple2":
            this.color = NicoColor.purple2; break;
          #endregion
          #region その他
          case "184":
            this.is184 = true; break;
          case "sage":
            this.sage = true; break;
          case "invisible":
            this.invisible = true; break;
          case "from_button":
            this.from_button = true; break;
          case "is_button":
            this.is_button = true; break;
          case "mobile":
            this.mobile = true; break;
          case "all":
            this.all = true; break;
          #endregion
        }

        if (Regex.IsMatch(temp[n], "#[0-9a-fA-F]{6}"))
          this.colorText = temp[n];
      }
    }

    public override string ToString()
    {
      return base.ToString();
    }

    #endregion Override Methods

    #endregion Protected Methods

    #region Private Methods

    #endregion Private Methods

  }
}
